changeIcon()
setRem()
window.onresize=function(){
	changeIcon()
	setRem()
};
/*
修改图标
 */
function changeIcon(){
	var userAgent=navigator.userAgent
	var html = document.querySelector("html")
	var type
	html.className=""
	if(userAgent.indexOf("iPhone")!=-1)
	{
		type="iPhone"
	}
	else if(userAgent.indexOf("Android")!=-1)
	{
		type=("andriod")
	}
	else if(userAgent.indexOf("iPad")!=-1)
	{
		type=("ipad")
	}
	else
	{
		type=("PC")
	}
	var use=document.querySelector("use")
	use.href.baseVal="#icon-"+type
};
/*
初始化rem
 */
function setRem(){
	var srceenWidth = window.innerWidth
	var danwei = srceenWidth/3.6
	var html = document.querySelector("html")
	var use=document.querySelector("use")
	if(use.href.baseVal=="#icon-PC"){
		html.style.fontSize = 160+'px'
		if(window.innerWidth<=300){
			html.style.width=300+"px"
		}
		else{
			html.style.width=srceenWidth+"px"
		}
	}
	else{
		html.style.fontSize = danwei+'px'
		html.style.width=srceenWidth+"px"
	}
}
/*
function fontNumber(content){
	var length = content.length
	if (length > 30) {
	    var str = ''
	    str = content.slice(0, 30) + '......'
	    return str
	  } else {
	    return date
	  }
}
*/
/*
交互内容
 */
var doingObjectList = []
var doneObjectList = []
// 获取正在进行和完成进行的元素
var doingNumDiv = document.querySelector(".doing .num")
var doneNumDiv = document.querySelector(".done .num")
var doingListDiv = document.querySelector(".doing .list")
var doneListDiv = document.querySelector(".done .list")
var doingList = Object.values(doingListDiv.children)
var doneList = Object.values(doneListDiv.children)
var inputDom = document.querySelector("#input")
/*
初始化
 */
render()
/*
回车事件
 */
inputDom.onkeydown = function(event){
	if (event.key == "Enter") {
		var content = inputDom.value
		if (content!="") {
			if (!isInDoingList(content) && !isInDoneList(content)) {
				addDoingList(content)
				setList()
			}
			inputDom.value = ""	
		}
	}
}
/*
勾选复选框事件
 */
doingListDiv.onchange = function(event){
	var oldChild = event.target.parentElement
	var content = oldChild.children[1].innerHTML
	doingListDiv.removeChild(oldChild)
	addDoneList(content)
	setList()
}
doneListDiv.onchange = function(event){
	var oldChild = event.target.parentElement
	var content = oldChild.children[1].innerHTML
	doneListDiv.removeChild(oldChild)
	addDoingList(content)
	setList()
}
/*
删除按钮
 */
doingListDiv.onclick = function(event){
	if (event.target.className=="del") {
		var oldChild = event.target.parentElement
		doingListDiv.removeChild(oldChild)
		setList()
	}
}
doneListDiv.onclick = function(event){
	if (event.target.className=="del") {
		var oldChild = event.target.parentElement
		doneListDiv.removeChild(oldChild)
		setList()
	}
}
/*
获取列表
 */
function setList(){
	doingObjectList = []
	doneObjectList = []
	doingList = Object.values(doingListDiv.children)
	doneList = Object.values(doneListDiv.children)
	doingList.forEach(function(item,index){
		var content = item.children[1].innerHTML
		doingObjectList.push(content)
	})
	doneList.forEach(function(item,index){
		var content = item.children[1].innerHTML
		doneObjectList.push(content)
	})
	doingNumDiv.innerHTML = doingObjectList.length
	doneNumDiv.innerHTML = doneObjectList.length

	localStorage.doingObjectList = JSON.stringify(doingObjectList)
	localStorage.doneObjectList = JSON.stringify(doneObjectList)
}
function render(){

	if (localStorage.getItem("doingObjectList") != null) {
		var doingObjectList = Object.values(JSON.parse(localStorage.doingObjectList)) 

		doingObjectList.forEach(function(item,index){
		addDoingList(item)
	})
	}
	if (localStorage.getItem("doneObjectList") != null) {
		var doneObjectList = Object.values(JSON.parse(localStorage.doneObjectList)) 

		doneObjectList.forEach(function(item,index){
		addDoneList(item)
	})
	}
	setList()
}
/*
判断内容是否存在列表当中
 */
function isInDoingList(value){
	//循环List里面的item
	for (var i = doingObjectList.length - 1; i >= 0; i--) {
		var content=doingObjectList[i] 
		if (value==content) {
			// console.log("存在")
			return true
		}
		else{
			// console.log("不存在")
		}	
	}
	return false
}
function isInDoneList(value){
	//循环List里面的item
	for (var i = doneObjectList.length - 1; i >= 0; i--) {
		var content=doneObjectList[i]
		if (value==content) {
			// console.log("存在")
			return true
		}
		else{
			// console.log("不存在")
		}	
	}
	return false
}
/*
添加元素到DoingList
 */
function addDoingList(content){
	var todoItem = document.createElement("div")
	todoItem.className = "todoItem"
	todoItem.innerHTML = `<input type="checkbox"/>
					<div class="content">`+content+`</div>
					<div class="del">-</div>`
	doingListDiv.appendChild(todoItem)
}
function addDoneList(content){
	var todoItem = document.createElement("div")
	todoItem.className = "todoItem"
	todoItem.innerHTML = `<input type="checkbox" checked="checked"/>
					<div class="content">`+content+`</div>
					<div class="del">-</div>`
	doneListDiv.appendChild(todoItem)
}

